package demo3;

import demo2.Emp;

import java.util.Iterator;
import java.util.Set;

public class TestSet {
    public void addEmp(Set<demo2.Emp> Set, demo2.Emp emp){
        Set.add(emp);
    }
    public void findAllEmp(Set<demo2.Emp> set){
        for (demo2.Emp emp: set){
            System.out.println(set);
        }
    }
    public Emp findEmpName(Set<Emp> set,String empName){
        for (Emp emp:set){
            if (empName.equals(emp.getName())){
                return emp;
            }
        }
        return null;
    }
    public void deleteEmp(Set<demo2.Emp> set, String empNumber){
        Iterator <Emp>  iterator=set.iterator();
        while (iterator.hasNext()){
            Emp emp=iterator.next();
            if (empNumber.equals(emp.getNumber())){
                iterator.remove();
            }
        }
        for (demo2.Emp emp: set){
            if (empNumber.equals(emp.getNumber())){
                set.remove(emp);
            }
        }
    }
    public demo2.Emp EmpNumber(Set<demo2.Emp> set, String empNumber){
        for (demo2.Emp emp: set){
            if (empNumber.equals(emp.getNumber())){
                return emp;
            }
        }
        return null;
    }

    public void changeEmpAge(Set<Emp> set,String empNumber,int empAge){

        for (Emp emp:set){
            if (empNumber.equals(emp.getNumber())){
                emp.setAge(empAge);
                return;
            }
        }
        System.out.println("未找到对应员工编号");
    }
}
